﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TerrainGenerator
{
    class TerrainGenerator
    {
        Perlin perlin;

        public TerrainGenerator(Perlin perlin)
        {
            this.perlin = perlin;
        }

        public Terrain GenerateTerrain(int width, int height, float dx, float dy, float magnitude)
        {
            return new Terrain(GenerateHeightmap(width, height, dx, dy, magnitude));
        }

        public float[,] GenerateHeightmap(int width, int height, float dx, float dy, float magnitude)
        {
            float[,] heightmap = new float[width, height];
            for (int x = 0; x < width; ++x)
            {
                for (int y = 0; y < height; ++y)
                {
                    heightmap[x, y] = (float)(magnitude * perlin.Compute(x * dx, y * dy));
                }
            }
            return heightmap;
        }

        public Terrain GenerateTerrain(int width, int height)
        {
            return GenerateTerrain(width, height, 0.1f, 0.1f, 10.0f);
        }
    }
}
